using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PanelManager
{
    private Stack<BasePanel> stackPanel;
    private UIManager uimanager;
    private BasePanel panel;
    public PanelManager()
    {
        stackPanel = new Stack<BasePanel>();
        uimanager = new UIManager();
    }
    public void Push(BasePanel nextPanel)
    {
        if (stackPanel.Count > 0)
        {
            panel = stackPanel.Peek();
            panel.OnPause();
        }
        GameObject panelobject = uimanager.GetSingleUI(nextPanel.uitype);
        nextPanel.Initialize(new UITool(panelobject));
        nextPanel.Initialize(this);
        nextPanel.Initialize(uimanager);
        stackPanel.Push(nextPanel);
        nextPanel.OnEnter();
        
    }
    public void PopAndPush(BasePanel nextPanel)
    {
        Pop();
        Push(nextPanel);
    }
    public void Pop()
    {
        if (stackPanel.Count > 0)
        {
            stackPanel.Peek().OnExit();
            stackPanel.Pop();
        }
        if (stackPanel.Count > 0)
        {
            stackPanel.Peek().OnResume();
        }
    }
    public void PopAll()
    {
        while (stackPanel.Count > 0)
        {
            stackPanel.Peek().OnExit();
            stackPanel.Pop();
        }
    }
}
